<?php

namespace App\Models\ReturnProduct;

use App\Models\Setting;
use App\Services\MobileApp\AppEnv;
use Illuminate\Database\Eloquent\Model;

class ReturnStatus extends Model
{
    const RETURN_STATUS_DEFAULT = 1; // 待审核
    const RETURN_STATUS_AWAITING_PRODUCTS = 2; // 等待寄回商品
    const RETURN_STATUS_COMPLETE = 3; // 已完成
    const RETURN_STATUS_REFUSE_RETURN = 4; // 已拒绝
    const RETURN_STATUS_REFUNDED = 5; // 已退款

    protected $table = 'return_status';
    protected $guarded = [];


    /**
     * @param $store_id
     * @return int|mixed
     */
    public static function getReturnStatusDefault($store_id)
    {
        $return_status_default = (new Setting)->where('store_id', $store_id)
            ->where('key', 'config_return_status_id')
            ->first();

        $return_status_id = $return_status_default->value ?? self::RETURN_STATUS_DEFAULT;

        return $return_status_id;
    }

    /**
     * @param $store_id
     * @return null
     */
    public static function getReturnStatusDefaultName($store_id)
    {
        $return_status_id_default = self::getReturnStatusDefault($store_id);

        $return_status = (new self)->where('language_id', AppEnv::languageId())
            ->where('return_status_id', $return_status_id_default)
            ->first();

        return $return_status->name ?? null;
    }
}
